const app = getApp();
Page({
  data: {
    items: [],
    selectIdList: [],
    querymemo: '暂无数据',
    isNoData: true,
  },
  onShow() {
    this.queryData();
  },
  queryData() {
    // 页面加载
    dd.showLoading({
      content: '加载中...',
      delay: 1000,
    });
    var that = this;
    dd.httpRequest({
      url: 'http://www.ejzcat.com/DingApi/EquipmentRepair/Query.ashx',
      method: 'POST',
      data: {
        status: 0,
        userid: app.globalData.userid
      },
      dataType: 'json',
      async: false,
      success: function(res) {
        dd.hideLoading();
        if (res.data.Items.length == 0) {
          that.setData({
            querymemo: '暂无数据',
            isNoData: true
          });
        }
        else {
          that.setData({
            querymemo: '',
            isNoData: false
          });
        }
        that.setData({
          items: res.data.Items
        });
      },
      fail: function(err) {
        dd.alert({ content: JSON.stringify(err) });
      }
    });
  },
  onEvaluate(e) {
    //dd.alert({ title: e.currentTarget.id });
    dd.navigateTo({
      url: '../../../mypages/equipment/evaluateform/index?id=' + e.currentTarget.id,
      success: function(res) {

      },
      fail: function(err) {

      },
      complete: function(res) {

      }
    })
  },
  onAllCheckChange(e) {
    var that = this;
    var list = [];
    var items = that.data.items;
    if (e.detail.value == true) {
      for (var i = 0; i < items.length; i++) {
        items[i].Checked = true;
        list.push(items[i].Id);
      }
    }
    else {
      for (var i = 0; i < items.length; i++) {
        items[i].Checked = false;
      }
    }
    that.setData({
      items: items,
      selectIdList: list
    })
  },
  onCheckChange(e) {
    var id = e.currentTarget.id;
    var that = this;
    var list = that.data.selectIdList;
    if (e.detail.value == true) {
      list.push(id);
    }
    else {
      for (var i = 0; i < list.length; i++) {
        if (id == list[i]) {
          list.splice(i, 1);
        }
      }
    }
    that.setData({
      selectIdList: list
    })
  },
  onSubmit() {
    //dd.alert({ title: JSON.stringify(this.data.selectIdList) });
    if (this.data.selectIdList.length == 0) {
      dd.alert({ content: '请选中需要评价的报修单' });
    }
    else {
      dd.navigateTo({
        url: '../../../mypages/equipment/evaluateform/index?ids=' + this.data.selectIdList,
        success: function(res) {

        },
        fail: function(err) {

        },
        complete: function(res) {

        }
      });
    }
  },
  onMessage(e) {
    var id = e.currentTarget.id;
    //dd.alert({ content: e.currentTarget.id });
    dd.navigateTo({
      url: '../../../mypages/equipment/message/message?id=' + id,
    })
  },
})